package com.sptpc.exam;

import com.sptpc.exam.model.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/useredit.do")
public class UserEditServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int uid = Integer.parseInt(request.getParameter("uid"));
        List<User> users =(List<User>)request.getSession().getAttribute("users");
        User user = null;
        for(User u : users){
            if(u.getUid() == uid){
                user = u;
                break;
            }
        }

        request.setAttribute("euser",user);
        request.getRequestDispatcher("useredit.jsp").forward(request,response);
    }
}
